﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbPayOnlinesDal
	{
		public DbPayOnlinesDal()
		{
		}
 		#region Insert
 		public static int Insert(DbPayOnlines dbPayOnlines)
		{	
			string sql = @"Insert Into DbPayOnlines (
					PoCode,
					PoName,
					PoUser,
					PoPartnerId,
					PoKeys,
					PoUrl,
					PoLogo,
					PoStatus,
					PoAddTime,
					PoType,
					PoReturnUrl,
					PoFee,
					PoNotifyUrl
				) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7},'{8}',{9},'{10}',{11},'{12}')";
			sql = string.Format(sql,
					SqlHelper.String(dbPayOnlines.PoCode),
					SqlHelper.String(dbPayOnlines.PoName),
					SqlHelper.String(dbPayOnlines.PoUser),
					SqlHelper.String(dbPayOnlines.PoPartnerId),
					SqlHelper.String(dbPayOnlines.PoKeys),
					SqlHelper.String(dbPayOnlines.PoUrl),
					SqlHelper.String(dbPayOnlines.PoLogo),
					dbPayOnlines.PoStatus,
					dbPayOnlines.PoAddTime,
					dbPayOnlines.PoType,
					SqlHelper.String(dbPayOnlines.PoReturnUrl),
					dbPayOnlines.PoFee,
					SqlHelper.String(dbPayOnlines.PoNotifyUrl)
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbPayOnlines dbPayOnlines)
		{	
			string sql = @"Update DbPayOnlines set 

					PoCode= '{0}',
					PoName= '{1}',
					PoUser= '{2}',
					PoPartnerId= '{3}',
					PoKeys= '{4}',
					PoUrl= '{5}',
					PoLogo= '{6}',
					PoStatus= {7},
					PoAddTime= '{8}',
					PoType= {9},
					PoReturnUrl= '{10}',
					PoFee= {11},
					PoNotifyUrl= '{12}'
				where

					PoId= {13}";
			sql = string.Format(sql,
					SqlHelper.String(dbPayOnlines.PoCode),
					SqlHelper.String(dbPayOnlines.PoName),
					SqlHelper.String(dbPayOnlines.PoUser),
					SqlHelper.String(dbPayOnlines.PoPartnerId),
					SqlHelper.String(dbPayOnlines.PoKeys),
					SqlHelper.String(dbPayOnlines.PoUrl),
					SqlHelper.String(dbPayOnlines.PoLogo),
					dbPayOnlines.PoStatus,
					dbPayOnlines.PoAddTime,
					dbPayOnlines.PoType,
					SqlHelper.String(dbPayOnlines.PoReturnUrl),
					dbPayOnlines.PoFee,
					SqlHelper.String(dbPayOnlines.PoNotifyUrl),
					dbPayOnlines.PoId);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 poId)
		{
		
			string sql = @"Delete from DbPayOnlines where 
					PoId= {0}";
			sql = string.Format(sql,
					poId
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbPayOnlines a "; 
			return SqlHelper.Select(sql);
		}
				
		public static DbPayOnlines Select(Int32 poId)
		{
			DbPayOnlines dbPayOnlines = null;
			string sql = @"select a.* from DbPayOnlines a  where
					a.PoId= {0}
";
			sql = string.Format(sql,
					poId
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				dbPayOnlines = new DbPayOnlines(ds.Tables[0].Rows[0]);					
			return dbPayOnlines;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbPayOnlines a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbPayOnlines a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbPayOnlines a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
